package chapter10_1_coutdown_latch;

import chapter6_2_condition.ConditionTest;
import sun.misc.PostVMInitHook;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author Summerday
 */
public class JoinCountDownLatch {

    public static volatile CountDownLatch countDownLatch = new CountDownLatch(2);

    public static void main (String[] args) throws InterruptedException {

        Thread A = new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + " finish!");

            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                countDownLatch.countDown();
            }
        }, "A");

        Thread B = new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + " finish!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                countDownLatch.countDown();
            }

        }, "B");

        A.start();
        B.start();

        System.out.println("main thread wait ..");

        countDownLatch.await();

        System.out.println("all thread finish !");

    }

}
